<template>
  <div id="speech">  

  <el-form ref="form"  label-width="80px">  

           <el-row>  
            <el-col :span="12" style="display:flex;">
               <div style="height:38px;line-height:38px;width:150px;"> 
                  <i class="el-icon-back" @click="goBack"></i> 
                  {{ $route.query.name }} 
                </div>
            </el-col> 
            <el-col :span="12" style="text-align: right;">
               <el-button type="primary" class="custom_color_button" style="margin-bottom:10px;" @click="add_but()">添加话术</el-button>   
            </el-col>   
        </el-row>

    </el-form>

   <!-- 渲染数据list -->
   <speech-list :data="data"  @up_list_fun="list_fun"> </speech-list>

   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"  
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>
      
         <!-- 添加话术 -->
    <el-dialog title="添加话术" :visible.sync="add_mtk"  width="500px" :close-on-click-modal="false">
        <div style="width:100%;"> 


        <el-form ref="form"   label-width="70px" style="width:100%;">

            <el-form-item label="话术">
                        <el-input  v-model="mtk_form.content" placeholder="添加话术"></el-input>
            </el-form-item>        
                              

        </el-form>
  
            
        <div style="text-align: center;width:50%;margin:auto;">
            <el-button type="primary" class="custom_color_button" style="width:80%;" @click="add_qr_but()">确认</el-button>
        </div>

        </div>
    </el-dialog>
    

      
  </div>
</template>

<script>
import SpeechList from '@/view/Aftersale/SpeechList'
export default {
  name: 'speech',
  data () {
    return {
        data:[],
        page:1,
        count:0,
        my_id:'',
        add_mtk:false,
        mtk_form:{
            content:''
        },
    }
  },
 components:{
    SpeechList
  },
  created(){
      this.my_id = this.$route.query.id
      this.list_fun()
  },
  mounted (){
    
  },
  methods: {
 
    list_fun(){
         
        this.post("/customer_service/listOfSpeechcraft", {
                page:this.page,
                csid:this.my_id,
            }).then(res => {
              this.count = res.result.count
              this.data = res.result.list
              //console.log(res)
            })
          
      },
    add_but(){
         this.add_mtk = true
         this.mtk_form.content = ''
    },
    add_qr_but(){
         this.post("/customer_service/addSpeechcraft", {
                csid:this.my_id,
                content:this.mtk_form.content
              }).then(res => {
                if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.add_mtk = false
                    this.list_fun()
                }else {
                    this.open1(res.message,'warning')
                }

            })
    },
    goBack() {
        this.$router.go(-1)
    },
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
        this.page = val
        this.list_fun()
        console.log(`当前页: ${val}`);
      }
  }
}
</script>


<style scoped>
</style>
